package com.forevershine.business.persistent.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.forevershine.business.persistent.EmployeeDao;
import com.forevershine.business.persistent.IDataAccessor;
import com.forevershine.personel.model.Employee;

public class EmployeeDaoImpl implements EmployeeDao{

	@Override
	public Integer save(Employee employee, IDataAccessor dataAccessor) {
		 SqlSession session = dataAccessor.getSession();
		 Integer i = session.insert("insertEmployee",employee);
		 session.commit();
		 session.close();
		 return i;
	}

	@Override
	public List load(IDataAccessor dataAccessor) {
		SqlSession session = dataAccessor.getSession();
		return session.selectList("selectEmployees");
	}

	@Override
	public void update(IDataAccessor dataAccessor, Employee employee) {
		SqlSession session = dataAccessor.getSession();
		session.update("updateEmployee", employee);
		session.commit();
		session.close();
	}

	@Override
	public void add(IDataAccessor dataAccessor, Employee employee) {
		SqlSession session = dataAccessor.getSession();
		session.insert("addEmployee", employee);
		session.commit();
		session.close();
	}

	@Override
	public void delete(IDataAccessor dataAccessor, Employee employee) {
		SqlSession session = dataAccessor.getSession();
		session.delete("deleteEmployee", employee);
		session.commit();
		session.close();
		
	}

}
